package muslim30;

/* 
 * Created on 2004. 9. 13.
 * 
 */
import java.math.BigInteger;

public class RSACryptor{
    final static String CHARSET = "KSC5601";    
    final static BigInteger PQ = 
        new BigInteger("38273202181053342373720828359470946084951365392157800998873879910659978637721");
    final static BigInteger PUBLIC_KEY = 
        new BigInteger("75622614615999602910823208617426644593");
    final static BigInteger PRIVATE_KEY = 
        new BigInteger("29339381419334396896556888439873755375647473146222206104684591098080885000337");
    
    public String encrypt(String _srcText)throws Exception{
        String encString;
        
        try{
            BigInteger src = new BigInteger(1, _srcText.getBytes(CHARSET));
            BigInteger enc = src.modPow(PUBLIC_KEY, PQ);
            encString = enc.toString();
        }catch(Exception e){
            encString = "";
  					e.printStackTrace();
						throw new Exception(e.getMessage());
        }        
        return encString;
    }
    
    public String decrypt(String _encText)throws Exception{
        String decString;
        try{
            BigInteger src = new BigInteger(_encText);
            BigInteger dec = src.modPow(PRIVATE_KEY, PQ);
            decString = new String(dec.toByteArray(), CHARSET);
        }catch(Exception e){
            decString = "";
  					e.printStackTrace();
						throw new Exception(e.getMessage());
        }
        return decString;
    }
}
